/*************************************************************************
    > File Name: fuzz.c
    > Author: ma6174
    > Mail: ma6174@163.com 
    > Created Time: 2016年10月12日 星期三 09:23:19
 ************************************************************************/

#include<stdio.h>
static int input_defuzz_abs_event(int value, int old_val, int fuzz)
{

	if (fuzz) {
		if (value > old_val - fuzz / 2 && value < old_val + fuzz / 2)
			return old_val;
		if (value > old_val - fuzz && value < old_val + fuzz)
			return (old_val * 3 + value) / 4;
		if (value > old_val - fuzz * 2 && value < old_val + fuzz * 2)
			return (old_val + value) / 2;
	}
	return value;
}
int main(void) 
{
	int old_val = 1000;
	int new_vals[]={100,800,850,900,950,1000,1050,1100};
	int fuzzs[]={5,10,15,20};
	int i,j;
	for (i=0; i<sizeof(fuzzs)/sizeof(int); i++){
		for (j=0; j<sizeof(new_vals)/sizeof(int); j++) {
		printf("fuzz:%d new_val:%04d result:%04d\n", fuzzs[i], new_vals[j], input_defuzz_abs_event(new_vals[j], old_val, fuzzs[i]));
		}
	}

}
